var account_ops = {
    init: function () {
        this.eventBind();
    },
    eventBind: function () {
        $('.form-group .save').click(function (ev) {
            ev.preventDefault();

            var params = common_ops.getParams();
            var method = params['m'];

            var nickname_i = $('.form-group input[name=nickname]');
            var mobile_i = $('.form-group input[name=mobile]');
            var email_i = $('.form-group input[name=email]');
            var login_name_i = $('.form-group input[name=login_name]');
            var login_pwd_i = $('.form-group input[name=login_pwd]');

            var nickname = nickname_i.val();
            var mobile = mobile_i.val();
            var email = email_i.val();
            var login_name = login_name_i.val();
            var login_pwd = login_pwd_i.val();

            if (nickname==null || nickname.length<1) {
                common_ops.tip('姓名不能为空', nickname_i);
                return;
            }
            if (mobile==null || mobile.length<1 || mobile.length>13) {
                common_ops.tip('手机号码不符合规范', mobile_i);
                return;
            }
            if (email==null || email.length<1) {
                common_ops.tip('邮箱不能为空', email_i);
                return;
            }
            if (login_name==null || login_name.length<1) {
                common_ops.tip('登录账号不能为空', login_name_i);
                return;
            }
            if (login_pwd==null || login_pwd.length<6 || login_pwd.length>20) {
                common_ops.tip('请输入6-20位中英文字符', login_pwd_i);
                return;
            }
            if (method==null) {
                common_ops.alert('提交数据格式不正确');
                return;
            }

            $.ajax({
                url: '/account/set',
                data: {
                    'nickname': nickname,
                    'mobile': mobile,
                    'email': email,
                    'login_name': login_name,
                    'login_pwd': login_pwd,
                    'method': method,
                    'id': params['id']
                },
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    if (data['code'] == 200) {
                        common_ops.alert('修改成功');
                        window.location.href = '/account/index'
                    }
                    else {
                        common_ops.alert(data['msg'])
                    }
                },
                fail: function () {
                        common_ops.alert('数据修改失败，请重试');
                }
            });
        });
    }
};

$(function () {
    account_ops.init();
});